package com.bobamrz.service;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.TreeMap;

import com.bobamrz.dao.DocTypeDAO;
import com.bobamrz.domain.DocStatusType;
import com.bobamrz.domain.DocType;

public class DocTypeService {
	
	private DocTypeDAO docTypeDAO = new DocTypeDAO();
	
	public List<Map<String, Object>> getAvailableDocTypes() {
		List<DocType> superDocTypes = docTypeDAO.getSuperDocTypesList();
		List<Map<String, Object>> result = new ArrayList<Map<String, Object>>();
		for(DocType superDocType : superDocTypes) {
			Map<String, Object> docTypeGroupMap = new TreeMap<String, Object>();
			docTypeGroupMap.put("groupName", superDocType.getTypeName());
			
			Set<DocType> subDocTypes = superDocType.getDocTypes();
			List<Map<String, String>> groupTypeList = new ArrayList<Map<String, String>>();
			for(DocType subDocType : subDocTypes) {
				Map<String, String> subTypeMap = new TreeMap<String, String>();
				subTypeMap.put("value", subDocType.getTypeName());//not ID
				subTypeMap.put("text", subDocType.getTypeName());
				groupTypeList.add(subTypeMap);
			}
			docTypeGroupMap.put("groupTypes", groupTypeList);
			result.add(docTypeGroupMap);
		}
		return result;
	}
	
	public List<DocType> getAvailableSuperDocTypes() {
		return docTypeDAO.getSuperDocTypesList();
	}

}
